//member_details
var hasDetailsErr = false;

function checkEmail(){
	var v = E("email").value;
	if(!isEmail(v)){
		hasDetailsErr = true ;
		E("email_tips").innerHTML = "<span class='errStyle'>请输入正确的Email地址</span>"; 
	}else{
		E("email_tips").innerHTML = "<span class='yesStyle'>该Email填写正确</span>"; 		
	}
}


function checkDetailsAction(){
	hasDetailsErr = false;
	checkEmail();
	if(!hasDetailsErr){
		popwin.loading();
		ajaxPost("detailsform","ajaxmember.php?action=modifyDetails", details_callback);
	}
}


function details_callback(data){
	popwin.loaded();
	var btns=[];
	if(data=="y"){
		btns=[
			{value:"确 定",onclick:"javascript:popwin.close()",focus:true}
		];
		popwin.showDialog(1,"修改成功","恭喜您，会员资料修改成功。",btns,320,140);
	}else{
		btns=[
			{value:"确 定",onclick:"popwin.close()",focus:true}
		];
		popwin.showDialog(0,"修改失败","会员资料修改失败，原因如下：<br />"+data,btns,320,140);
	}
}

function details_PageInit(){
	E("birthday").onfocus = function(){choosedate.dfd(E('birthday'))};
	E("email").onblur = checkEmail;
	setRadioCheck("user[sex]", member_sex);
}



//member_msg
function delMsg_success(){
	btns=[
		{value:"确 定",onclick:"javascript:popwin.close();window.location.href=window.location.href;",focus:true}
	];
	popwin.showDialog(1,"删除成功","短信删除成功",btns,380,140);
}

function popedom3_tips(){
	btns=[
		{value:"确 定",onclick:"javascript:popwin.close();",focus:true}
	];
	popwin.showDialog(2,"操作提示","您所在的用户组没有权限发送短信。",btns,380,140);
}

//member_password
var hasPassErr = false;

function checkOldPassword(){
	var v = E("oldpass").value;
	if(v==""){
		hasPassErr = true;
		E("oldpass_tips").innerHTML = "<span class='errStyle'>必须填写</span>";
	}
	else{
		E("oldpass_tips").innerHTML = "";
	}
}

function checkPassword(){
	var v = E("userpass").value;
	if(v==""||getLength(v)<6||getLength(v)>16){
		hasPassErr = true;
		E("userpass_tips").innerHTML = "<span class='errStyle'>长度必须为：6-16位字符</span>";
	}else{
		E("userpass_tips").innerHTML = "<span class='yesStyle'>&nbsp;</span>";
	}
}

function checkRePassword(){
	var v = E("userpass").value;
	var rv = E("repass").value;
	if(rv==""||v!=rv){
		hasPassErr = true;
		E("repass_tips").innerHTML = "<span class='errStyle'>请重复输入上面的密码</span>";
	}else{
		E("repass_tips").innerHTML = "<span class='yesStyle'>&nbsp;</span>";
	}
}

function checkChangePass(){
	hasPassErr = false;
	checkOldPassword();
	checkPassword();
	checkRePassword();
	if(!hasPassErr){
		popwin.loading();
		ajaxPost("pass_form","ajaxmember.php?action=modifyPass",pass_callback);
	}
}

function pass_callback(data){
	popwin.loaded();
	var btns=[];
	if(data=="y"){
		btns=[
			{value:"确 定",onclick:"javascript:popwin.close()",focus:true}
		];
		popwin.showDialog(1,"修改成功","恭喜您，密码修改成功。<br />请在下次登录使用新密码。",btns,320,140);
		E("userpass").value = "";
		E("oldpass").value = "";
		E("repass").value = "";
	}else{
		btns=[
			{value:"确 定",onclick:"popwin.close()",focus:true}
		];
		popwin.showDialog(0,"修改失败","密码修改失败，原因如下：<br />"+data,btns,320,140);
	}
}

function password_PageInit(){
	E("userpass").onkeyup = function(){pwStrength(E("userpass").value, 'strength', 6);};
}

function msg_selectall(b){
	var oForm=getE("membermsg_form");
	for (var i = 0; i < oForm.elements.length; i++) {
		if(oForm.elements[i].type=="checkbox"&&!oForm.elements[i].disabled){
			oForm.elements[i].checked = b;
		}
	}
}

function deleteMsgs(){
	popwin.loading();
	ajaxPost("membermsg_form","ajaxmember.php?action=deleteMsgs",deleteMsgs_callback);
}

function deleteMsgs_callback(data){
	popwin.loaded();
	window.location.reload();
}

